package net;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.Socket;

import util.DeviceInfo;

public class UserNetReaderThread extends Thread {

	Socket SockCliente;
	NetComunicationLayer com;
	public String name;
	public int port;

	@Override
	public void run() {
		String Entrada;
		String emi = SockCliente.getInetAddress().getHostName();
		String ip = SockCliente.getInetAddress().getHostAddress();
		util.DeviceInfo device = new DeviceInfo(emi, ip);
		try {
			BufferedReader lector = new BufferedReader(new InputStreamReader(
					SockCliente.getInputStream()));
			System.out.println("UNRT: " +emi +" conected.");
			try {
				while (true) {

					Entrada = lector.readLine();
					Entrada = Entrada.trim();
					com.addActionComand(device, Entrada);
				}
			} catch (Exception e) {
				// TODO: handle exception
				SockCliente.close();
			}

		} catch (Exception e) {
		}

	}

	public UserNetReaderThread(Socket SockClientin,
			NetComunicationLayer comlayer) {
		SockCliente = SockClientin;
		com = comlayer;
	}
}